//
//  OilHeadView.m
//  Base_App
//
//  Created by Yutian Duan on 2019/5/30.
//  Copyright © 2019年 Wanwin. All rights reserved.
//

#import "OilHeadView.h"

@interface OilHeadView ()

@property (nonatomic, strong) UIImageView *bgImageView;
///! title
@property (nonatomic, strong) UILabel *titleLabel;
//! 未登录UI
@property (nonatomic, strong) UIView *unLoginView;
///! 未绑定UI
@property (nonatomic, strong) UIView *unBindView;
///!
@property (nonatomic, strong) UIView *isBindView;

///! 油量
@property (nonatomic, strong) UILabel *oilCountLabel;

@property (nonatomic, strong) UIButton *bindButton;

@end

@implementation OilHeadView

- (UIView *)unLoginView {
  if (!_unLoginView) {
    _unLoginView = [[UIView alloc] initWithFrame:CGRectMake(0, _titleLabel.yt_bottom, ScreenWidth, _bgImageView.yt_height - _titleLabel.yt_bottom)];
    [_bgImageView addSubview:_unLoginView];
    
    UILabel *tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, _unLoginView.yt_width, 20)];
    tipLabel.text = YTLocalizedString(@"你仍未登入已注册之");
    tipLabel.textColor = [UIColor whiteColor];
    tipLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
    tipLabel.textAlignment = NSTextAlignmentCenter;
    [_unLoginView addSubview:tipLabel];
    
    UIImageView *logoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(tipLabel.yt_left, tipLabel.yt_bottom+10, 196, 14)];
    logoImageView.image = [UIImage imageNamed:@"Notice_logo"];
    [_unLoginView addSubview:logoImageView];
    
    UILabel *accountLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, logoImageView.yt_top, 0, logoImageView.yt_height+1)];
    accountLabel.text = YTLocalizedString(@"账户");
    accountLabel.textColor = [UIColor whiteColor];
    accountLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
    [accountLabel sizeToFit];
    [_unLoginView addSubview:accountLabel];
    
    //
    logoImageView.yt_centerX = _unLoginView.yt_width/2 - accountLabel.yt_width/2;
    
    accountLabel.yt_left = logoImageView.yt_right + 5;
    
  }
  return _unLoginView;
}

- (UIView *)unBindView {
  if (!_unBindView) {
    _unBindView = [[UIView alloc] initWithFrame:CGRectMake(0, _titleLabel.yt_bottom, ScreenWidth, _bgImageView.yt_height - _titleLabel.yt_bottom)];
    [_bgImageView addSubview:_unBindView];
    
    UILabel *tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, _unLoginView.yt_width, 20)];
    tipLabel.text = YTLocalizedString(@"你仍未绑定任何油咭");
    tipLabel.textColor = [UIColor whiteColor];
    tipLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
    tipLabel.textAlignment = NSTextAlignmentCenter;
    [_unBindView addSubview:tipLabel];

    
    UIButton *bindButton = [[UIButton alloc] initWithFrame:CGRectMake(0, tipLabel.yt_bottom + 10, 44, 30)];
    [bindButton setImage:[UIImage imageNamed:@"Oil_bindCard"] forState:UIControlStateNormal];
    [bindButton addTarget:self action:@selector(bindCard) forControlEvents:UIControlEventTouchUpInside];
    bindButton.yt_centerX = tipLabel.yt_centerX;
    [_unBindView addSubview:bindButton];

  }
  return _unBindView;
}

///
- (UIView *)isBindView {
  if (!_isBindView) {
    _isBindView = [[UIView alloc] initWithFrame:CGRectMake(0, _titleLabel.yt_bottom, ScreenWidth, _bgImageView.yt_height - _titleLabel.yt_bottom)];
    [_bgImageView addSubview:_isBindView];
    
    ///
    UILabel *oilLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, _isBindView.yt_width, 20)];
    oilLabel.textAlignment = NSTextAlignmentCenter;
    oilLabel.text = YTLocalizedString(@"本月入油量");
    oilLabel.textColor = [UIColor whiteColor];
    oilLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
    [_isBindView addSubview:oilLabel];
    
    ///!
    _oilCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, oilLabel.yt_bottom, _isBindView.yt_width - 60, 30)];
    _oilCountLabel.textAlignment = NSTextAlignmentCenter;
    _oilCountLabel.textColor = [UIColor whiteColor];
    _oilCountLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:20.0f];
    [_isBindView addSubview:_oilCountLabel];
    
    ///
    UILabel *tipLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, _oilCountLabel.yt_bottom + 5, _isBindView.yt_width, 12)];
    tipLabel.textColor = [UIColor lightGrayColor];
    tipLabel.textAlignment = NSTextAlignmentCenter;
    tipLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:13.0f];
    tipLabel.text = YTLocalizedString(@"点击查看入油记录");
    [_isBindView addSubview:tipLabel];
    
    


  }
  return _isBindView;
}



- (instancetype)initWithFrame:(CGRect)frame {
  self = [super initWithFrame:frame];
  if (self) {
    [self setDefaultView];
  }
  return self;
}

- (void)setDefaultView {
  
  _bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.yt_width, self.yt_height)];
  _bgImageView.clipsToBounds = YES;
  _bgImageView.contentMode = UIViewContentModeScaleAspectFill;
  _bgImageView.image = [UIImage imageNamed:@"Oil_head_login"];
  _bgImageView.userInteractionEnabled = YES;
  [self addSubview:_bgImageView];
  

  //！
  _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 40, 120, 40)];
  _titleLabel.text = YTLocalizedString(@"油咭");
  _titleLabel.textColor = [UIColor whiteColor];
  _titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:20.0f];
  [_bgImageView addSubview:_titleLabel];
  _titleLabel.yt_bottom = _bgImageView.yt_height/2;

  //!
  ///! 添加油咭，需要已经添加油咭之后才显示
  _bindButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 30)];
  [_bindButton setImage:[UIImage imageNamed:@"Oil_bindCard"] forState:UIControlStateNormal];
  [_bindButton addTarget:self action:@selector(bindCard) forControlEvents:UIControlEventTouchUpInside];
  _bindButton.yt_centerY = _titleLabel.yt_centerY;
  _bindButton.yt_right = _bgImageView.yt_width - 30;
  [_bgImageView addSubview:_bindButton];
  _bindButton.hidden = YES;
  
  
  
}

- (void)reloadView {
  
  _unLoginView.hidden = YES;
  _unBindView.hidden = YES;
  _isBindView.hidden = YES;
  _bindButton.hidden = YES;

  _bgImageView.image = [UIImage imageNamed:@"Oil_head_login"];

  if ([ToolsServer sharedInstance].isLoginApp == NO) {
    //! 未登录
    self.unLoginView.hidden = NO;
  } else {
    ///! 已登录
    if ([ToolsServer sharedInstance].isBindCard == NO) {
      self.unBindView.hidden = NO;
    } else {
      self.isBindView.hidden = NO;
      _bindButton.hidden = NO;
      _bgImageView.image = [UIImage imageNamed:@"Home_BgImage"];
      _oilCountLabel.text = @"0.00L";
    }

  }
  
  
}


///! 绑定油咭
- (void)bindCard {
  ///!
  if (self.bindOilClick) {
    self.bindOilClick();
  }  
  
}

@end
